-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Crystal::Tracing
for runtime tracing
#14659
Add Crystal::Tracing
for runtime tracing
#14659
Conversation
The internal runtime may need to access the current thread and scheduler before they're actually defined *and* without defining them (e.g. tracing).
Then let's do that, please 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
polish: Standardize format for calls to Crystal.trace
.
The section argument is always a symbol, the operation argument sometimes a symbol, sometimes a string.
Crystal.trace :sched, :spawn
Crystal.trace :sched, "event_loop"
It would be nice using the same format, maybe the operation could always be a string?
@straight-shoota following your review, I made the following changes:
|
Fixes a bug where it'd print the whole buffer despite not necessarily using it fully (when last char doesn't fit). Also no longer restricts the method to Windows; it might be useful in other cases?
Thanks @straight-shoota. I applied all your suggestions! |
I noticed that one macro used |
Crystal::Tracing
for runtime tracing
This pull request has been mentioned on Crystal Forum. There might be relevant details there: https://forum.crystal-lang.org/t/want-to-hear-a-feedback-on-debugging-support/7190/3 |
Implements tracing of the garbage collector and the scheduler as per #14618
Tracing is enabled by compiling with
-Dtracing
then individual tracing must be enabled at runtime with theCRYSTAL_TRACE
environment variable that is a comma separated list of sections to enable, for example:none
to disable everything (by default)gc
sched
gc,sched
all
to enable everythingThe traces are printed to the standard error by default, but this can be changed at runtime with the
CRYSTAL_TRACE_FILE
environment variable. For exampletrace.log
. You can also redirect the standard error to a file (e.g.2> trace.log
on UNIX shell).Technical note: tracing happens before the stdlib is initialized, so the implementation must rely on some
LibC
methods directly (i.e. read environment variable, write to file descriptor) and can't use the core/stdlib abstractions.Note: theDone: #14660Thread#current_thread?
commit could be extracted into a distinct PR.